# include<iostream>
# include<vector>
# include"NewtonFormula.h"
# include"Function.h"
# include"NewtonSolver.h"

using namespace::std;

# define N 7
# define SAMPLE 2

int main()
{
    double day[N] = {0, 6, 10, 13, 17, 20, 28};
    double Sp[SAMPLE][N] = {{6.67, 17.3, 42.7, 37.3, 30.1, 29.3, 28.7},
                           {6.67, 16.1, 18.9, 15.0, 10.6, 9.44, 8.89}};
    vector<struct node> Tree[SAMPLE];
    for (int i = 0; i < SAMPLE; i++)
    {
        for (int j = 0; j < N; j++)
        {
            struct node part{day[j], Sp[i][j]};
            Tree[i].push_back(part);
        }
    }

    NewtonFormula Solver1(Tree[0]);
    NewtonFormula Solver2(Tree[1]);

    // Sample 1 (a)
    cout << "Sample 1 :" << endl;
    Solver1.PrintPolCoff();
    Solver1.PrintPol();
    Polynomial p1(Solver1.GetPoly());
    // Sample 1 (b)
    NewtonSolver N1(28, 0.00001, 15, p1);
    double x1 = N1.solve();
    cout << "root is " << x1 << " p1(x) = " << p1(x1) << endl;
    cout << "15 days : Weight will be " << Solver1.sovle(43) << endl;

    // Sample 2 (a)
    cout << "Sample 2 :" << endl;
    Solver2.PrintPolCoff();
    Solver2.PrintPol();
    Polynomial p2(Solver2.GetPoly());
    // Sample 2 (b)
    NewtonSolver N2(28, 0.00001, 15, p2);
    double x2 = N2.solve();
    cout << "root is " << x2 << " p1(x) = " << p2(x2) << endl;
    cout << "15 days : Weight will be " << Solver2.sovle(43) << endl;
    
    cout << "Finish" << endl;
    return 0;
}